public class test1 {
    class Solution {
        public String simplifyPath(String path) {
            Deque<String> stack = new LinkedList<>();
            for(String str:path.split("/")){
                if(str.equals("..")){
                    if(!stack.isEmpty()){
                        stack.pop();
                    }
                }else if(!str.equals(".") && !str.equals("")){
                    stack.push(str);
                }
            }
            String res = "";
            for(String str:stack){
                //妙用！这样就不用倒来倒去了
                res = "/" + str + res;
            }
            return res.isEmpty()? "/" : res;
        }
    }
}
